/*******************************************************************************
 * Copyright (c) 2012 Clever Devices.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 * 	Clever Devices Interns - 
 * 	Alex Frankel, Andria Young, Kevin Thomas, Nicholas Culpepper, Taner Oztimurlenk, Thomas Volberg
 ******************************************************************************/
package com.framework.menu;

import java.util.List;

import com.framework.cleverstop_tentative.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Sets custom view for the sliding menu items in order to add image to left of text
 * 
 * @author AFrankel
 *
 */
public class MenuAdapter extends ArrayAdapter<MenuItem> {

	public MenuAdapter(Context context, int layoutResourceId, List<MenuItem> objects) {
		super(context, layoutResourceId, objects);
		this.context = context;
		data = objects;
		resourceId = layoutResourceId;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		MenuHolder holder = null;
		
		if(row==null){
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(resourceId,parent,false);
			
			holder = new MenuHolder();
			holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
			holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
			holder.rewardNumber = (TextView)row.findViewById(R.id.onlyReward);
			
			row.setTag(holder);
		}
		else{
			holder = (MenuHolder)row.getTag();
		}
		
		MenuItem menu = data.get(position);
		holder.txtTitle.setText(menu.description);
		holder.imgIcon.setImageResource(menu.icon);
		holder.rewardNumber.setText(menu.number);
		if(!menu.number.equals(""))
			holder.rewardNumber.setBackgroundResource(R.drawable.bluebutton);
			//holder.rewardNumber.setBackgroundColor(Color.BLUE);
		if(menu.description.equals("Alerts"))
			holder.rewardNumber.setTypeface(null,Typeface.BOLD);
		
		return row;
	}


	static class MenuHolder{
		ImageView imgIcon;
		TextView txtTitle;
		TextView rewardNumber;
	}


	Context context;
	List<MenuItem> data;
	int resourceId;
	
}
